#include<bits/stdc++.h>
#define int long long 
#define Maxn 200010 
using namespace std;
struct SGT {
	#define lson x<<1,l,mid 
	#define rson x<<1|1,mid+1,r 
	int sgt[Maxn<<2];
	void merge(int x,int l,int r,int u,int v,int w) {
		if(u<=l&&r<=v)return sgt[x] += w,void();
		int mid = (l+r)>>1; if(u <= mid)merge(lson,u,v,w); if(mid < v)merge(rson,u,v,w);
		sgt[x] = min(sgt[x<<1],sgt[x<<1|1]);
	} 
	int query(int x,int l,int r,int u,int v) {
		if(u<=l&&r<=v)return sgt[x];
		if(u > v||l == r)return 0;
		int mid = (l+r)>>1,ans = INT_MAX;
		if(u <= mid)ans = min(ans,query(lson,u,v));
		if(mid < v)ans = min(ans,query(rson,u,v));
		return ans;
	}
	#undef lson 
	#undef rson 
} tre1,tre2;
int a[Maxn],b[Maxn];
namespace SETB {
	int lc[Maxn];
	set<int> S,t;
	int fg[Maxn];
	struct node {
		int id,s;
		bool operator<(const node&is) 
		const{return s < is.s;}; 
	} p[Maxn];
	void into(int n) {
		for(int i=1;i<=n;i++)
			p[i].s = a[i],p[i].id = i;
		sort(p+1,p+1+n);
		lc[n] = 1; t.insert(n); S.insert(n);
		for(int i=1;i<=n;i++) {
			if(t.empty())continue;
			auto v = t.lower_bound(p[i].id);
			int a1 = lc[(*v)],a2 = p[i].id-1,a3 = p[i].id+1,a4 = (*v);
			S.erase(S.lower_bound((*v)-lc[(*v)]+1)); t.erase(v);
			if(a1 <= a2)lc[a2] = a1,t.insert(a2),S.insert(a2-a1+1);
			if(a3 <= a4)lc[a4] = a3,t.insert(a4),S.insert(a4-a3+1);
			if(!S.empty())fg[(*S.rend())] = p[i+1].s;
		} fg[n] = p[1].s;
		for(int i=n-1;i>0;i--)fg[i] = max(fg[i],fg[i+1]);
	}
}
void solve() {
	int n; cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i],tre1.merge(1,1,n,i,i,a[i]);
	for(int i=1;i<=n;i++)cin>>b[i],tre2.merge(1,1,n,i,i,b[i]);
	if(n <= 1000) {
		for(int i=1;i<=n;i++) {
			int ans = INT_MAX;
			for(int l=1;l+i-1<=n;l++)
				ans = min(ans,abs(tre1.query(1,1,n,l,l+i-1)-tre2.query(1,1,n,l,l+i-1)));
			cout<<ans<<"\n";
		} return void();
	}
	if(b[1] == 1) {
		for(int i=1;i<=n;i++)
			cout<<tre1.sgt[1]-1<<"\n";
		return void();
	}
	SETB::into(n);
	for(int i=1;i<=n;i++)cout<<1000000000-SETB::fg[i]<<"\n";
}
signed main()
{
	freopen("min.in","r",stdin);
//	freopen("min.out","w",stdout);
//	ios::sync_with_stdio(0);
//	cin.tie(0); cout.tie(0);
	solve(); 
	return 0;
 } 
